package com.spzx.cart.controller;

import com.spzx.cart.service.ICartService;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.common.security.annotation.RequiresLogin;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@Tag(name = "购物车接口")
@RestController
@RequestMapping
public class CartController extends BaseController {
    @Resource
    private ICartService cartService;

    @InnerAuth
    @GetMapping("/deleteCartCheckedList/{userId}")
    void deleteCartCheckedList(@PathVariable("userId")Long userId){
        cartService.deleteCartCheckedList(userId);
    }

    @InnerAuth
    @GetMapping("/updateCartPrice/{userId}")
    void updateCartPrice(@PathVariable("userId") Long userId){
        cartService.updateCartPrice(userId);
    }

    @InnerAuth
    @GetMapping("checkCart/{skuId}/{checkStatus}")
    public AjaxResult checkCart(@PathVariable Long skuId,@PathVariable Integer checkStatus){
        return success(cartService.checkCartList(skuId, checkStatus));
    }
    @Operation(summary = "添加购物车")
    @RequiresLogin
    @GetMapping("addToCart/{skuId}/{skuNum}")
    public AjaxResult addCart(@PathVariable Long skuId,@PathVariable Integer skuNum){
        cartService.addToCart(skuId,skuNum);
        return success();
    }

    @GetMapping("cartList")
    public AjaxResult getCarList(){
        return success(cartService.getCarList());
    }
    @DeleteMapping ("deleteCart/{skuId}")
    public AjaxResult delectCart(@PathVariable Long skuId){
        cartService.delectCart(skuId);
        return success();
    }
//    @GetMapping("checkCart/{skuId}/{isChecked}")
//    public AjaxResult checkCart(@PathVariable("skuId")Long skuId,@PathVariable("isChecked")Integer isChecked){
//        cartService.checkCart(skuId,isChecked);
//        return success();
//    }
    @GetMapping("allCheckCart/{isChecked}")
    public AjaxResult allCheckCart(@PathVariable Integer isChecked){
        cartService.allCheckCart(isChecked);
        return success();
    }
    @GetMapping("clearCart")
    public AjaxResult clearCart(){
        cartService.clearCart();
        return success();
    }
}
